<?php $this->load->view('header');?>

<div class="page-container">
	<?php $this->load->view('sidebar');?>
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<?php $this->load->view('user/_sub_nav');?>
			<div class="row">
				<div class="col-md-12">
					<div class="table-toolbar">
						<div class="btn-group">
							<button id="add_module_btn" class="btn green" data-toggle="modal" data-target="#add_module_modal">
							 新增模块 <i class="fa fa-plus"></i>
							</button>
						</div>
					</div>

					<table class="table">
						<thead>
							<tr>
								<th>父模块</th>
								<th>子模块</th>
								<th>操作权限</th>
								<th>操作URL</th>
								<th>对应图标</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach ($modules as $father):?>
								<tr class="active">
									<td><a href="#" data-type="text" data-pk="<?php echo $father['module_id'];?>" id ="module_name" class="module_name"><?php echo $father['module_name'];?></a></td>									
									<td></td>
									<td></td>
									<td><a href="#" data-type="text" data-pk="<?php echo $father['module_id'];?>" id="module_url" class="module_url"><?php echo $father['module_url'];?></a></td>
									<td><a href="#" data-type="text" data-pk="<?php echo $father['module_id'];?>" id ="module_icon" class="module_icon"><?php echo $father['module_icon'];?></a></td>
									<td>开放中</td>
									<td>
										<a class="btn btn-success btn-xs add_module_btn"  data-pk="<?php echo $father['module_id'];?>" data-toggle="modal" data-target="#add_module_modal">新增模块</a>
										<button class="btn btn-danger btn-xs module_del_btn" data-pk="<?php echo $father['module_id'];?>">删除</button>
									</td>
								</tr>
								<?php if(isset($father['childrens'])&&is_array($father['childrens'])&&count($father['childrens'])):?>
									<?php foreach($father['childrens'] as $children):?>
										<tr>
											<td></td>
											<td><a href="#" data-type="text" data-pk="<?php echo $children['module_id'];?>" id="module_name" class="module_name"><?php echo $children['module_name'];?></a></td>																		
											<td></td>
											<td><a href="#" data-type="text" data-pk="<?php echo $children['module_id'];?>" id="module_url" class="module_url"><?php echo $children['module_url'];?></a></td>
											<td><a href="#" data-type="text" data-pk="<?php echo $children['module_id'];?>" id="module_icon" class="module_icon"><?php echo $children['module_icon'];?></a></td>	
											<td>开放中</td>
											<td>
												<a class="btn btn-success btn-xs add_action_btn" data-target="#add_action_modal" data-toggle="modal" data-pk="<?php echo $children['module_id'];?>" data-title="<?php echo $children['module_name'];?>" >新增动作</a>
												
												<button class="btn btn-danger btn-xs module_del_btn" data-pk="<?php echo $children['module_id'];?>">删除</button>
											</td>
										</tr>
										<?php if(isset($children['actions'])&&is_array($children['actions'])&&count($children['actions'])>0):?>
											<?php foreach($children['actions'] as $action):?>
												<tr>
													<td></td>
													<td></td>
													<td><a href="#" data-type="text" data-pk="<?php echo $action['action_id'];?>" id="action_name" class="action_name"><?php echo $action['action_name'];?></a></td>
													<td><a href="#" data-type="text" data-pk="<?php echo $action['action_id'];?>" id="action_url" class="action_url"><?php echo $action['action_url'];?></a></td>
													<td></td>
													<td>开放中</td>
													<td>												
														<button class="btn btn-danger btn-xs action_del_btn" data-pk="<?php echo $action['action_id'];?>">删除</button>
													</td>
												</tr>
											<?php endforeach;?>
										<?php endif;?>
									<?php endforeach;?>
								<?php endif;?>
							<?php endforeach;?>
						</tbody>
					</table>


					<div class="modal fade" id="add_module_modal">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
									<h4 class="modal-title">模块名称</h4>
								</div>
								<div class="modal-body">
									<form action="" method="POST" class="form-horizontal" role="form" id="add_module_form">
											<div class="form-group">
												<label class="control-label col-sm-2" for="module_father">父模块</label>
												<div class="col-sm-10">
													<select name="father" id="module_father" class="form-control" required="required">
														<option value="0">顶级模块</option>
														<?php foreach($father_modules as $module):?>
															<option value="<?php echo $module['module_id'];?>"><?php echo $module['module_name'];?></option>
														<?php endforeach;?>
													</select>
												</div>
											</div>
											<div class="form-group">
												<label class="control-label col-sm-2" for="module_name"><span class="required">*</span>模块名称</label>
												<div class="col-sm-10">
													<input type="text" id="module_name" class="form-control" name="name" placeholder="权限名称"/>
												</div>
											</div>
											<div class="form-group">
												<label class="control-label col-sm-2" for="module_url">模块URL</label>
												<div class="col-sm-10">
													<input type="text" id="module_url" name="url" class="form-control" placeholder="权限描述"/>
												</div>
											</div>
											<div class="form-group">
												<label class="control-label col-sm-2" for="module_icon">ICON图标</label>
												<div class="col-sm-10">
													<input type="text" id="module_icon" name="icon" class="form-control" placeholder="对应图标class"/>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2">状态</label>
												<div class="col-md-10">
													<div class="radio-list">
														<label class="radio-inline">
															<input type="radio" name="status" id="input" value="" checked="checked">
															开放
														</label>														
														<label class="radio-inline">
															<input type="radio" name="status" id="input" value="" >
															关闭
														</label>														
													</div>
												</div>
											</div>									
								
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
									<button type="submit" class="btn btn-primary" id="permAddBtn">保存</button>
								</div>
								</form>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div><!-- /.modal -->
					
					<div class="modal fade" id="add_action_modal">
						<div class="modal-dialog">
							<div class="modal-content">
								<form action="" method="POST" class="form-horizontal" role="form" id="add_action_form">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
									<h4 class="modal-title">新增动作</h4>
								</div>
								<div class="modal-body">
									<div class="form-group">
										<label class="control-label col-sm-2" for="module_name_input"><span class="required">*</span>模块名称</label>
										<div class="col-sm-10">
											<input type="text" id="module_name_input" class="form-control" placeholder="权限名称" disabled="disabled" />
											<input type="hidden" name="module" value="" id="module_hidden_input">
										</div>
									</div>

									<div class="form-group">
										<label class="control-label col-sm-2" for="module_name"><span class="required">*</span>动作名称</label>
										<div class="col-sm-10">
											<input type="text" id="module_name" class="form-control" name="name" placeholder="权限名称"/>
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-2" for="module_url">对应URL</label>
										<div class="col-sm-10">
											<input type="text" id="module_url" name="url" class="form-control" placeholder="权限描述"/>
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-2" for="module_icon">ICON图标</label>
										<div class="col-sm-10">
											<input type="text" id="module_icon" name="icon" class="form-control" placeholder="对应图标class"/>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2">状态</label>
										<div class="col-md-10">
											<div class="radio-list">
												<label class="radio-inline">
													<input type="radio" name="status" id="input" value="" checked="checked">
													开放
												</label>														
												<label class="radio-inline">
													<input type="radio" name="status" id="input" value="" >
													关闭
												</label>														
											</div>
										</div>
									</div>	
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
									<button type="submit" class="btn btn-primary">保存设置</button>
								</div>
								</form>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div><!-- /.modal -->

				</div>
			</div>
	</div>
</div>

<?php $this->load->view('footer');?>

<script type="text/javascript" src="assets/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
<!-- Jquery Form -->
<script type="text/javascript" src="assets/plugins/jquery.form.js"></script>
<!-- Jquery Form -->
<script type="text/javascript" src="assets/scripts/custom/module.js"></script>

<script>
jQuery(document).ready(function() {    
   App.init(); // initlayout and core plugins
   Module.init();
});
</script>

</body>
<!-- END BODY -->
</html>
